package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IAccountView
import de.baumann.browser.model.UserModel

/**
 *@author:
 *@date:2019/10/24 14:56
 *@discription: 账号注册 和 密码找回
 */
class AccountPasswordPresenter : BasePresenter<IAccountView>() {
    private val userModel = UserModel()

    fun getSmsCode(token:String="") {
        this.userModel.registerGetSmsCode(view.telNum,token)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        if (view != null)
                            view.smsCodeSent()
                    }
                })
    }

    fun register() {
        this.userModel.register(view.telNum, view.password, view.smsCode, view.otherCode)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        if (view != null)
                            view.requestSuccess()
                    }
                })
    }

    fun retrieveGetSmsCode(token:String) {
        this.userModel.retrieveGetSmsCode(view.telNum,token)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        if (view != null)
                            view.smsCodeSent()
                    }
                })
    }

    fun resetPassword() {
        this.userModel.resetPassword(view.telNum, view.password, view.otherCode, view.smsCode)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        if (view != null)
                            view.requestSuccess()
                    }
                })
    }
}